/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.loja.view.swing;

import java.awt.Component;
import java.awt.Container;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JScrollPane;

/**
 *
 * @author DavidLuiz
 */
public class ComponentUtil {

    static Map<String, Component> getComponents(Container container) {

        Map<String, Component> listComponent = Collections.EMPTY_MAP;

        if (container.getComponentCount() > 0) {
            listComponent = new HashMap<>();

            for (Component component : container.getComponents()) {
                if (component.getName() != null) {
                    if (component instanceof JScrollPane) {
                        listComponent.putAll(getComponents(((JScrollPane) component).getViewport()));
                    } else {
                        listComponent.put(component.getName(), component);
                    }
                }
            }

        }

        return listComponent;
    }

}
